﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
using Utility;
namespace Service
{
    /// <summary>
    /// 功能：Student2027类数据访问
    /// 创建人：Wilson
    /// 创建时间：2013-1-30   
    /// </summary>
    public class Student2027Service : IDisposable
    {
        #region 公共
        private System.ComponentModel.Component component = new System.ComponentModel.Component();

        private bool disposed = false;

        ~Student2027Service()
        {
            Dispose(false);
        }

        #endregion

        #region IDisposable 成员

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {

                if (disposing)
                {

                    component.Dispose();
                }

                disposed = true;

            }
        }
        #endregion
		#region##MapperStudent2027
        public IList<Student2027> MapperList(SqlDataReader reader)
         {
            IList<Student2027> list = new List<Student2027>();
            Student2027 obj=null;
            while (reader.Read())
            {
                obj = new Student2027();
                obj.StYear = (string)reader["StYear"];
                obj.StudentCode2 = (string)reader["StudentCode2"];
                obj.CityId = (string)reader["CityId"];
                obj.DistrictId2 = (string)reader["DistrictId2"];
                obj.StSchool = (string)reader["StSchool"];
                obj.StGrade = (string)reader["StGrade"];
                obj.StClass = (string)reader["StClass"];
                obj.Name = (string)reader["Name"];
                obj.MobilePhone = reader["MobilePhone"] as string;
                obj.StudentType = reader["StudentType"] as string;
                obj.BornDate = reader["BornDate"] as DateTime?;
                obj.Nation = reader["Nation"] as string;
                obj.EnterDate = reader["EnterDate"] as DateTime?;
                obj.Address = reader["Address"] as string;
                obj.Phone = reader["Phone"] as string;
                obj.Status = (string)reader["Status"];
                list.Add(obj);
            }
            return list;
         }
        public Student2027 Mapper(SqlDataReader reader)
         {
            Student2027 obj=null;
            if (reader.Read())
            {
                obj = new Student2027();
                obj.StYear = (string)reader["StYear"];
                obj.StudentCode2 = (string)reader["StudentCode2"];
                obj.CityId = (string)reader["CityId"];
                obj.DistrictId2 = (string)reader["DistrictId2"];
                obj.StSchool = (string)reader["StSchool"];
                obj.StGrade = (string)reader["StGrade"];
                obj.StClass = (string)reader["StClass"];
                obj.Name = (string)reader["Name"];
                obj.MobilePhone = reader["MobilePhone"] as string;
                obj.StudentType = reader["StudentType"] as string;
                    obj.BornDate = reader["BornDate"] as DateTime?;
                obj.Nation = reader["Nation"] as string;
                    obj.EnterDate = reader["EnterDate"] as DateTime?;
                obj.Address = reader["Address"] as string;
                obj.Phone = reader["Phone"] as string;
                obj.Status = (string)reader["Status"];
            }
            return obj;
         }
        #endregion
        #region##通过主键ID得到Student2027
        /// <summary>
        /// 功能：通过ID得到Student2027
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
        public Student2027 GetById(string styear)
        {            
            string sql = "select * from Student2027 where StYear = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",6)
            };
            
            SqlDataReader reader=SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql,sp);
            return Mapper(reader);
        }
        #endregion
		
		#region##通过主键ID删除Student2027
        /// <summary>
        /// 功能：通过主键ID删除Student2027
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(string styear)
		{
			int i = 0;
			string sql = "delete from Student2027 where StYear = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",6)
            };
            i= SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
			return i;
		}
        /// <summary>
        /// 功能：通过主键ID删除Student2027
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(SqlTransaction transaction,string styear)
		{
			int i = 0;
			string sql = "delete from Student2027 where StYear = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",6)
            };
            i= SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
			return i;
		}
		#endregion			
		
        #region##添加Student2027
        /// <summary>
        /// 功能：添加Student2027
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(Student2027 student2027)
        {
            int result = 0;
            string sql = "insert into Student2027(StYear,StudentCode2,CityId,DistrictId2,StSchool,StGrade,StClass,Name,MobilePhone,StudentType,BornDate,Nation,EnterDate,Address,Phone,Status) values(@StYear,@StudentCode2,@CityId,@DistrictId2,@StSchool,@StGrade,@StClass,@Name,@MobilePhone,@StudentType,@BornDate,@Nation,@EnterDate,@Address,@Phone,@Status)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@StYear",student2027.StYear),
				new SqlParameter("@StudentCode2",student2027.StudentCode2),
				new SqlParameter("@CityId",student2027.CityId),
				new SqlParameter("@DistrictId2",student2027.DistrictId2),
				new SqlParameter("@StSchool",student2027.StSchool),
				new SqlParameter("@StGrade",student2027.StGrade),
				new SqlParameter("@StClass",student2027.StClass),
				new SqlParameter("@Name",student2027.Name),
				new SqlParameter("@MobilePhone",student2027.MobilePhone),
				new SqlParameter("@StudentType",student2027.StudentType),
				new SqlParameter("@BornDate",student2027.BornDate),
				new SqlParameter("@Nation",student2027.Nation),
				new SqlParameter("@EnterDate",student2027.EnterDate),
				new SqlParameter("@Address",student2027.Address),
				new SqlParameter("@Phone",student2027.Phone),
				new SqlParameter("@Status",student2027.Status)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：添加Student2027
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(SqlTransaction transaction,Student2027 student2027)
        {
            int result = 0;
            string sql = "insert into Student2027(StYear,StudentCode2,CityId,DistrictId2,StSchool,StGrade,StClass,Name,MobilePhone,StudentType,BornDate,Nation,EnterDate,Address,Phone,Status) values(@StYear,@StudentCode2,@CityId,@DistrictId2,@StSchool,@StGrade,@StClass,@Name,@MobilePhone,@StudentType,@BornDate,@Nation,@EnterDate,@Address,@Phone,@Status)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@StYear",student2027.StYear),
				new SqlParameter("@StudentCode2",student2027.StudentCode2),
				new SqlParameter("@CityId",student2027.CityId),
				new SqlParameter("@DistrictId2",student2027.DistrictId2),
				new SqlParameter("@StSchool",student2027.StSchool),
				new SqlParameter("@StGrade",student2027.StGrade),
				new SqlParameter("@StClass",student2027.StClass),
				new SqlParameter("@Name",student2027.Name),
				new SqlParameter("@MobilePhone",student2027.MobilePhone),
				new SqlParameter("@StudentType",student2027.StudentType),
				new SqlParameter("@BornDate",student2027.BornDate),
				new SqlParameter("@Nation",student2027.Nation),
				new SqlParameter("@EnterDate",student2027.EnterDate),
				new SqlParameter("@Address",student2027.Address),
				new SqlParameter("@Phone",student2027.Phone),
				new SqlParameter("@Status",student2027.Status)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##得到Student2027集合
		/// <summary>
        /// 功能：得到Student2027集合
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>       
        /// <returns></returns>
		public IList<Student2027> GetList()
		{
			string sql = "select * from Student2027";			
			SqlDataReader reader = SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql);
            return MapperList(reader);
		}
		#endregion
		
		#region##修改Student2027
        /// <summary>
        /// 功能：修改Student2027
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModStudent2027(Student2027 student2027)
        {
            int result = 0;
            string sql = "update Student2027 set StYear = @StYear,StudentCode2 = @StudentCode2,CityId = @CityId,DistrictId2 = @DistrictId2,StSchool = @StSchool,StGrade = @StGrade,StClass = @StClass,Name = @Name,MobilePhone = @MobilePhone,StudentType = @StudentType,BornDate = @BornDate,Nation = @Nation,EnterDate = @EnterDate,Address = @Address,Phone = @Phone,Status = @Status where StYear = @StYear";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@StYear",student2027.StYear),
				new SqlParameter("@StudentCode2",student2027.StudentCode2),
				new SqlParameter("@CityId",student2027.CityId),
				new SqlParameter("@DistrictId2",student2027.DistrictId2),
				new SqlParameter("@StSchool",student2027.StSchool),
				new SqlParameter("@StGrade",student2027.StGrade),
				new SqlParameter("@StClass",student2027.StClass),
				new SqlParameter("@Name",student2027.Name),
				new SqlParameter("@MobilePhone",student2027.MobilePhone),
				new SqlParameter("@StudentType",student2027.StudentType),
				new SqlParameter("@BornDate",student2027.BornDate),
				new SqlParameter("@Nation",student2027.Nation),
				new SqlParameter("@EnterDate",student2027.EnterDate),
				new SqlParameter("@Address",student2027.Address),
				new SqlParameter("@Phone",student2027.Phone),
				new SqlParameter("@Status",student2027.Status)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：修改Student2027
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModStudent2027(SqlTransaction transaction,Student2027 student2027)
        {
            int result = 0;
            string sql = "update Student2027 set StYear = @StYear,StudentCode2 = @StudentCode2,CityId = @CityId,DistrictId2 = @DistrictId2,StSchool = @StSchool,StGrade = @StGrade,StClass = @StClass,Name = @Name,MobilePhone = @MobilePhone,StudentType = @StudentType,BornDate = @BornDate,Nation = @Nation,EnterDate = @EnterDate,Address = @Address,Phone = @Phone,Status = @Status where StYear = @StYear";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@StYear",student2027.StYear),
				new SqlParameter("@StudentCode2",student2027.StudentCode2),
				new SqlParameter("@CityId",student2027.CityId),
				new SqlParameter("@DistrictId2",student2027.DistrictId2),
				new SqlParameter("@StSchool",student2027.StSchool),
				new SqlParameter("@StGrade",student2027.StGrade),
				new SqlParameter("@StClass",student2027.StClass),
				new SqlParameter("@Name",student2027.Name),
				new SqlParameter("@MobilePhone",student2027.MobilePhone),
				new SqlParameter("@StudentType",student2027.StudentType),
				new SqlParameter("@BornDate",student2027.BornDate),
				new SqlParameter("@Nation",student2027.Nation),
				new SqlParameter("@EnterDate",student2027.EnterDate),
				new SqlParameter("@Address",student2027.Address),
				new SqlParameter("@Phone",student2027.Phone),
				new SqlParameter("@Status",student2027.Status)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##统计Student2027
		/// <summary>
        /// 修改Student2027
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
		public int SelectCount()
		{
			int i = 0;
            string sql = "select count(*) from Student2027";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
		}
		/// <summary>
        /// 修改Student2027
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int SelectCountById()
        {
            int i=0;
            string sql="select count(StYear) from Student2027";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
        }
		#endregion
        #region##自定义Student2027
        #endregion
                
    }
}
